<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
<head>
<title>辅助核算期初设置</title>
</head>
<body>	
	<script type="text/javascript" >
	    var ye=0;
		$(function() {
			dataGrid = $('#dataGrid').edatagrid({
				url : '${pageContext.request.contextPath}/business/accounting/fzhsqcsz/QClist.shtml',
				fit : true,
				border : false,
				pagination : true,
				idField : 'id',
				pageSize : 20,
				pageList : [ 10, 20, 30, 40, 50 ],
				sortName : 'ID',
				sortOrder : 'ASC',
				checkOnSelect : false,
				selectOnCheck : false,
				nowrap : false,
				striped : true,
				rownumbers : true,
				singleSelect : true,
				columns : [[
				              {field : 'ID',title : 'ID',align : 'center'}, 
							  {field : 'KJND',title : '会计年度',align : 'center',hidden:true}, 
							  {field : 'HSLXBM',title : '核算类型',align : 'center',hidden:true}, 
				              {field : 'KMBH',title : '科目编码',width : 145,align : 'center'}, 
                              {field : 'KMMC',title : '科目名称',width : 145,align : 'center'}, 
                              {field : 'KMYEFX',title : '科目方向',width : 145,align : 'center'},
                              {field : 'HSXMBM',title : '核算项目编码',width : 145,align : 'center'},
                              {field : 'HSXMMC',title : '核算项目名称',width : 145,align : 'center'},
                              {field : 'NCYE',title : '年初余额',width : 145,align : 'center',editor:'text'},
                              {field : 'BNLJJF',title : '本年累计借方',width : 145,align : 'center',editor:'text'},
                              {field : 'BNLJDF',title : '本年累计贷方',width : 145,align : 'center',editor:'text'},
                              {field : 'YUE',title : '余额',width : 145,align : 'center',editor:'text'}
				]],
				toolbar : '#toolbar',
				onLoadSuccess : function() {
					$('#searchForm table').show();
					parent.$.messager.progress('close');
					$(this).datagrid('tooltip');
				},
				onClickRow:function(rowIndex, rowData){
				 	var editors = $('#dataGrid').datagrid('getEditors', rowIndex);
		        	for (var i = 0, len = editors.length; i < len; i++) {
		        		var editor = editors[i];
			        	$(editor.target).bind('blur', function (e) {
			        		console.info(editors);
			        		var row =$("#dataGrid").datagrid("getRows")
							 var rowIndex1 = $("#dataGrid").datagrid("getRowIndex", row)	;
							 var jf = row.BNLJJF;
							 var df = row.BNLJDF;
							 var ye = jf-df;
							 $('#dataGrid').datagrid('updateRow',{
									index: rowIndex1,
									row: {
										YUE: ye,
									}
								}); 							
			        	});
		        	}
				},
				/**onLoadSuccess : function() {
					 $(".datagrid-row").mouseleave(function(){  
						 var row = $("#dataGrid").datagrid("getSelected");
						 
						 var rowIndex = $("#dataGrid").datagrid("getRowIndex", row);
						 var jf = row.BNLJJF;
						 var df = row.BNLJDF;
						 var ye = jf-df;
						 $('#dataGrid').datagrid('updateRow',{
								index: rowIndex,
								row: {
									YUE: ye,
								}
							}); 										 
						 });
				},**/
				onRowContextMenu : function(e, rowIndex, rowData) {
					e.preventDefault();
					$(this).datagrid('unselectAll');
					$(this).datagrid('selectRow', rowIndex);
					$('#menu').menu('show', {
						left : e.pageX,
						top : e.pageY
					});
				}
			});
			
		  //==============
		      
		  //==============			  
		});
		
		
		function searchFun() {
		    dataGrid.datagrid('load', $.serializeObject($('#searchForm')));
			    setTimeout("abc()",1000);
		}
		
		function abc(){
			 var ye=0;
		var rows = $("#dataGrid").datagrid("getRows");
			for (var i = 0; i < rows.length; i++) { 
				var a=rows[i].YUE;
		        ye+=a;
				}
		    $("#yue").val(ye);
		}
		
		function cleanFun() {
			$('#searchForm input').val('');
			dataGrid.datagrid('load', {});
		}
		$('#cwkm').combobox({
			url:'${pageContext.request.contextPath}/business/accounting/fzhsqcsz/cwkm.shtml',
		    valueField:'KMBH',
		    textField:'KMMC'
		});
		$('#hslx').combobox({
			url:'${pageContext.request.contextPath}/business/accounting/fzhsqcsz/hslx.shtml',
		    valueField:'HSLXBM',
		    textField:'HSLXMC'
		});
		
		function add()
		{
		
	  	var editIndex = $('#dataGrid').datagrid('getRowIndex', $('#dataGrid').datagrid('getSelected'));
	  	$('#dataGrid').datagrid('endEdit', editIndex);
	  	var insertRows = $('#dataGrid').datagrid('getChanges');
    	
    	var changesRows = {
    	    	inserted : []
    	    						};
				   	if (insertRows.length>0) {
				   	for (var i=0;i<insertRows.length;i++) {
				   	changesRows.inserted.push(insertRows[i]);
				  	 	}
				   	}

			$.ajax({
			 	 type: "post",   
			     url: "${pageContext.request.contextPath}/business/accounting/fzhsqcsz/add.shtml",
			     data: "inserted="+JSON.stringify(changesRows.inserted),   
			 	 datatype: "json",
			 	 success:function(data){
			 		parent.$.messager.progress('close');
			 		data = $.parseJSON(data);
					if (data.success) {
						parent.$.messager.alert('成功', data.msg, 'success');
					} else {
						parent.$.messager.alert('错误', data.msg, 'error');
					}
			          } 
			    })
			}
		
		
		

	</script>
	<div class="text clearfix" style="text-align: center;">
	<div>&nbsp;&nbsp;</div>
	<span style="algin: center"> <a class="l-btn"
		id="QC_query_form_search_button"><span class="l-btn-left"><span
				class="l-btn-text icon-search l-btn-icon-left" onclick="searchFun()">查询</span></span></a>
		&nbsp;&nbsp; <a class="l-btn" id="reset_button"><span
			class="l-btn-left"><span class="l-btn-text" onclick="cleanFun()">重置</span></span></a>
		&nbsp;&nbsp;<a  onclick="add()" class="l-btn" id="add_button"><span
			class="l-btn-left"><span class="l-btn-text">存盘</span></span></a>
		&nbsp;&nbsp;
	</span>
	<div>&nbsp;&nbsp;</div>
</div>
	<div class="easyui-layout" data-options="fit : true,border : false">
		<div data-options="region:'north',title:'',border:false" style="height: 100px; overflow: hidden;" >
			<form id="searchForm">
				<table class="form_view_border" bordercolordark="#FFFFFF" bordercolorlight="#45b97c" border="px" cellpadding="0" cellspacing="0" >
				<tr>
							<th class="panel-header">会计年度</th>
								 <td style="width: 160px">
	                                 <input name="KJND" class="easyui-combobox" id="mkid" style="width: 180px;height: 27px;"  
	                                 data-options="url:'${pageContext.request.contextPath}/business/accounting/fuzhuhesuan/kjnd.shtml',
										method: 'get',valueField:'name', textField:'name', panelHeight:'auto'" >  
	                            </td>
							<th class="panel-header">财务科目</th>
	                               	<td style="width: 160px">               
                                <input class="easyui-combobox" id="cwkm" name = "CWKM" style="width: 190px;height: 27px;" data-options="valueField:'KMBH', textField:'KMMC', panelHeight:'auto'" >  
<!-- 	                            </td> -->
<!-- 						<th class="panel-header">核算类型</th> -->
<!-- 	                               	<td style="width: 160px">                -->
<!--                                 <input class="easyui-combobox" id="hslx" name = "HSLX" style="width: 190px;height: 27px;" data-options="valueField:'HSLXBM', textField:'HSLXMC', panelHeight:'auto'" >   -->
<!-- 	                            </td> -->
						
						<th class="panel-header">科目余额</th>
						      	<td><input class="form_view_input combo 	easyui-textbox" id="yue" name="yue" style="width: 190px;height: 27px;" type="text" disabled="true" " ></td>
				</table>
			</form>
		</div>
		<div data-options="region:'center',border:false">
			<table id="dataGrid"></table>
		</div>
	</div>
</body>
</html>